package com.itheima.java.ai.langchin4j.server.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.java.ai.langchin4j.entity.DoctorSchedule;
import com.itheima.java.ai.langchin4j.mapper.DoctorScheduleMapper;
import com.itheima.java.ai.langchin4j.server.DoctorScheduleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;

@Service
public class DoctorScheduleServiceImpl extends ServiceImpl<DoctorScheduleMapper, DoctorSchedule> implements DoctorScheduleService {
    
    @Autowired
    private DoctorScheduleMapper doctorScheduleMapper;
    
    @Override
    public List<DoctorSchedule> getDoctorScheduleByDate(Long doctorId, LocalDate date) {
        return doctorScheduleMapper.findByDoctorIdAndDate(doctorId, date);
    }
    
    @Override
    public List<DoctorSchedule> getDoctorScheduleByDateRange(Long doctorId, LocalDate startDate, LocalDate endDate) {
        return doctorScheduleMapper.findByDoctorIdAndDateRange(doctorId, startDate, endDate);
    }
    
    @Override
    public List<DoctorSchedule> getAvailableSchedulesByDate(LocalDate date) {
        return doctorScheduleMapper.findAvailableByDate(date);
    }
    
    @Override
    public boolean bookTimeSlot(Long scheduleId) {
        return doctorScheduleMapper.bookSlot(scheduleId) > 0;
    }
    
    @Override
    public boolean cancelTimeSlot(Long scheduleId) {
        return doctorScheduleMapper.cancelSlot(scheduleId) > 0;
    }
    
    @Override
    public boolean isTimeSlotAvailable(Long scheduleId) {
        DoctorSchedule schedule = doctorScheduleMapper.selectById(scheduleId);
        return schedule != null && schedule.getAvailableSlots() > 0;
    }
}